package 滑动窗口;

public class LeetCode209_长度最小的子数组 {
    public static int minSubArrayLen(int target, int[] nums) {
        int i = 0;
        int j = i;
        int count = 0;
        int sum = 0;
        if (nums.length == 1 || nums.length == 0) {
            if (nums[i] == target) {
                return 1;
            }
            return 0;
        }
        while (j < nums.length) {
            sum += nums[j];
            while (sum >= target) {
                if (count == 0) {
                    count = j - i + 1;
                    sum -= nums[i];
                    i++;
                }else {
                    count = Math.min(count, j - i + 1);
                    sum -= nums[i];
                    i++;
                }

            }
            j++;
        }
        return count;
    }

    public static void main(String[] args) {
        int teger = 7;
        int[] nums = {2,3,1,2,4,3};
        int count = minSubArrayLen(teger,nums);
        System.out.println(count);
    }
}
